package com.edu.exam.enums.questionbank;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 验证规则类型枚举
 */
public enum ValidationRuleType implements BaseEnum {

    /**
     * 格式验证
     */
    FORMAT("FORMAT", "格式验证"),

    /**
     * 范围验证
     */
    RANGE("RANGE", "范围验证"),

    /**
     * 长度验证
     */
    LENGTH("LENGTH", "长度验证"),

    /**
     * 模式验证
     */
    PATTERN("PATTERN", "模式验证"),

    /**
     * 业务验证
     */
    BUSINESS("BUSINESS", "业务验证"),

    /**
     * 自定义验证
     */
    CUSTOM("CUSTOM", "自定义验证");

    private final String code;
    private final String description;

    ValidationRuleType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public String getJsonValue() {
        return code;
    }

    public static ValidationRuleType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return FORMAT;
        }

        for (ValidationRuleType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        return FORMAT;
    }
}